package actor

import "reflect"

type EMsgType int

const (
	System EMsgType = iota
	Normal
	Socket
	Client
)

type RpcMsg struct {
	Source  uint
	Session uint
	MsgType EMsgType
	Method  string
	Params  []interface{}
	retChan chan interface{}
}

type RetInfo struct {
	session uint
	// nil
	// interface{}
	// []interface{}
	ret interface{}
	err error
}

type Session struct {
	id uint
	c  chan *RetInfo
	cb func(interface{}, error)
}

type ForkSignal struct {
	f    func(...interface{})
	args []interface{}
}

// FunctionInfo handler接口信息
type FunctionInfo struct {
	Function  reflect.Value
	FuncType  reflect.Type
	InType    []reflect.Type
	Goroutine bool
}

type Actor interface {
	OnInit(app App, s Service, addr uint)
	Run(closeSig chan bool) (err error)
	GetAddr() uint
	GetService() Service
	OnDestroy()
	GetRpcChan() chan interface{}
	Close()
}

type App interface {
	Send(target interface{}, msg *RpcMsg) (err error)
	UniqueActor(actor Actor, s Service) (addr uint, err error)
	NewActor(actor Actor, s Service) (addr uint, err error)
	ActorExit(actor Actor) (err error)
}

type Service interface {
	OnInit()
	OnDestroy()
	Run(args interface{})
	Name() string
}
